package com.lanou.service;

import com.lanou.dao.StaffDao;
import com.lanou.dao.StaffDaoImpl;
import com.lanou.domain.CrmDepartment;
import com.lanou.domain.CrmStaff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lanouhn on 17/9/27.
 */
@Transactional
public class StaffServiceImpl implements StaffService{

    @Resource(name = "staffDao")
    private StaffDao staffDao;

    //进行用户登录的查询
    @Override
    public CrmStaff find(CrmStaff crmStaff) {
        return staffDao.find(crmStaff);
    }


    //查询所有员工信息
    @Override
    public List<CrmStaff> findAll() {
        return staffDao.findAll();
    }
    //根据id查询员工基本信息
    @Override
    public CrmStaff findById(String staffId) {
        return staffDao.findById(staffId);
    }


    //员工编辑更新

    @Override
    public void update(CrmStaff crmStaff) {
//        会自动提交
//        原因：一级缓存被修改了，与快照不一致，默认情况下，当提交，自动执行update
        CrmStaff findStaff=staffDao.findById(crmStaff.getStaffId());
        //如果不一致
//        if(!findStaff.getLoginPwd().equals(crmStaff.getLoginPwd())){
//            findStaff.setLoginPwd(CrmStringUtils.getMD5Value(crmStaff.getLoginPwd()));
//
//
//        }
        findStaff.setLoginName(crmStaff.getLoginName());
        findStaff.setStaffName(crmStaff.getStaffName());
        findStaff.setGender(crmStaff.getGender());
        findStaff.setOnDutyDate(crmStaff.getOnDutyDate());
        findStaff.setPost(crmStaff.getPost());
    }

    public StaffDao getStaffDao() {
        return staffDao;
    }

    public void setStaffDao(StaffDao staffDao) {
        this.staffDao = staffDao;
    }

    public void setStaffDao(StaffDaoImpl staffDao) {
        this.staffDao = staffDao;
    }
}
